package servlet;

import Day528.DB;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "saveUpdate", value = "/saveUpdate")
public class saveUpdate extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String sex = request.getParameter("sex");
        String sql = "update student set name=? sex=? where id=?";
        int i = 0;
        try {
            i = DB.update(sql);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        if (i > 0) {
            response.getWriter().write("修改成功");
        } else {
            response.getWriter().write("修改失败");
        }

    }
}

